<template>
	<view>
		<view class="search-nav">
			<view><uni-search-bar placeholder="搜索内容" radius="8" bgColor="#FFFFFF" @confirm="onSearch" @clear="onCancel" cancelButton="none" @input="onInput" /></view>
			<view class="p10-0">
				<text class="searchBtn" @click="onSearchBtn">搜索</text>
			</view>
		</view>
		<view class="p0-8">
			<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="120">
				<view v-for="item in baikeType" :key='item.name' class="scroll-view-item_H">
					<view :class="form.type == item.id ? 'tabs_' : 'tabs'" @click="onSelectType(item.id)">{{item.name}}</view>
				</view>
			</scroll-view>
		</view>
		<uni-row>
			<uni-col v-for="item in baikeInfo.list" :key='item.id' :span="12" >
				<view class="p8 mt10" @click="onLink('info/index',item.id)"><image style="width: 100%;border-radius: 3px;" :src="item.img" mode="widthFix"></image></view>
				<view class="p0-8 title">{{item.title}}</view>
				<uni-row class="p8">
					<uni-col :span="12">
						<view class="text-left p0-8 company">{{item.company_name}}</view>
					</uni-col>
					<uni-col :span="12">
						<view class="text-right p0-8 company"><uni-icons type="eye" size="15"></uni-icons>{{item.click_um}}</view>
					</uni-col>
				</uni-row>
			</uni-col>
		</uni-row>
		<uni-load-more :status="status" />
		
		<uni-popup ref="popupActivityTip" background-color="none">
			<activityTipVue @activityTipStatus="activityTipStatus"></activityTipVue>
		</uni-popup>
	</view>
</template>
<script>
	import activityTipVue from '../../components/activity_tip.vue'
	export default {
		components: {
			activityTipVue
		},
		data() {
			return {
				form:{page:1,type:0},
				selectType:0,
				baikeType: [],
				baikeInfo:{list:[],count:0,num:10,page:1},
				status:'more',
				loadData : true,
			}
		},
		onLoad() {
			// this.$refs.popupActivityTip.open('center')
		},
		onShow() {
			this.onGetBaikeType()
			this.onGetBaike()
		},
		methods: {
			onGetBaikeType(){
				let _this = this
				this.$request('/api2/wiki_type','GET').then(res => {
					_this.baikeType = _this.mapType(res.data.wiki)
				}).catch(err => {
					console.log(err)
				})
			},
			onGetBaike(){
				
				this.status = 'loading'
				if(!this.loadData){
					this.status = 'no-more'
					return false;
				}
				let _this = this
				let url = '/api2/wiki_next_page'
				if(this.form.title){
					url = '/api2/wiki_search'
				}
				this.$request(url,'POST',this.form).then(res => {
					_this.form.page = res.data.page + 1
					_this.baikeInfo.count = res.data.count
					_this.baikeInfo.page = res.data.page
					_this.baikeInfo.num = res.data.num
					if(res.data.list.length == 0){
						_this.loadData = false
						_this.status = 'no-more'
					}
					if(res.data.list.length <  res.data.num){
						_this.status = 'no-more'
					}
					_this.baikeInfo.list.push(...res.data.list) 
				}).catch(err => {
					console.log(err)
				})
			},
			onReachBottom() {
				this.onGetBaike()
			},
			onSelectType(id){
				this.form.page = 1
				this.form.type = id
				this.baikeInfo.list = []
				this.onGetBaike()
			},
			onSearch(e){
				this.form.title = e.value
				this.form.page = 1
				this.baikeInfo.list = []
				this.onGetBaike()
			},
			onInput(e){
				this.form.title = e
			},
			onSearchBtn(){
				this.form.page = 1
				this.baikeInfo.list = []
				this.onGetBaike()
			},
			onCancel(e){
				this.loadData = true
				this.form.title = ''
				this.form.page = 1
				this.baikeInfo.list = []
				this.onGetBaike()
			},
			mapType(data){
				let obj = { name: '全部', id: 0 }
				data.unshift(obj)
				return data.map((item) => {
					item.text = item.name
					item.value = item.id
					return item
				});
			},
			onLink(url,id){
				uni.navigateTo({
					url: "/pages/index/"+url+"?id="+id
				});
			},
			activityTipStatus(data){
				if(!data){
					this.$refs.popupActivityTip.close()
				}
			}
		}
	}
</script>

<style scoped lang="scss">
.scroll-view_H {white-space: nowrap;width: 100%;}
.title{font-size: .9rem;color: #111;font-weight: 600;height: 70rpx;line-height: 38rpx;}
.company{font-size: .8rem;margin-top: 5px;}
.node{border-top: 1px solid #EEE;padding: 24px 0px;}
.node-image{width: 55px;height: 55px;}
.text {font-size: 14px;margin: 5px 5px 5px 5px;overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical}
.grid-item-box {
	flex: 1;
	// position: relative;
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 10px 0;
}
</style>
